java创建类时方法的命名最好不要以is,get,set开头

您所在的位置:网站首页 java set get函数 java创建类时方法的命名最好不要以is,get,set开头

java创建类时方法的命名最好不要以is,get,set开头

2023-09-26 09:40| 来源: 网络整理| 查看: 265

在创建JavaBean时,为该类创建了多个成员方法,方法名命名成了getLeftInfo、getRightInfo、isMeet,结果提示了一连串的错误:

[ERROR]Servlet.service() for servlet [dispatcherServlet] in context with path [/cbs_futu_demo] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: No serializer found for class *.PosObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: *.ObjectJson["result"]->java.util.ArrayList[0]->*.pojo.Picture["leftPos"])] with root cause No serializer found for class *pojo.PosObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: *json.ObjectJson["result"]->java.util.ArrayList[0]->cn.com.trs.domain.pojo.Picture["leftPos"])

提示中说序列化出错,结合自己的代码想:难道是因为成员方法里返回的另一个类的对象序列化出错了吗,但是我并没有把该对象返回啊,debug、找同学解决,一直搞了两三个小时也不知道该怎么解决。第二天早上再仔细看错误提示,看到总有leftPos、rightPos这种字眼,心想代码里也没有写过这个啊,感觉是不知道把leftPos放哪儿的意思,这难道是把解决某一问题的过程的成员方法getLeftPos识别成成员变量的get方法了吗,试着把这些方法的方法名儿改了一下,果然编译通过了。因此,提醒大家:java创建类时方法的命名最好不要以is,get,set开头。同时,应该尽量避免属性名的头两个字母中任意一个为大写以及属性名以"is"开头。

查一下java函数的命名规范!(待查!)



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3